//
//  LGServiceExpiresCell.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2025/8/12.
//

#import "LGServiceExpiresCell.h"

@interface LGServiceExpiresCell()
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**  到期时间 */
@property (nonatomic , strong)UILabel *timeTitle;
@property (nonatomic , strong)UILabel *timeLabel;

/**  服务包 */
@property (nonatomic , strong)UILabel *serviceTitle;
@property (nonatomic , strong)UILabel *serviceLabel;
/**   */
@property (nonatomic , strong)UIButton *patientBtn;
/**   */
@property (nonatomic , strong)UIButton *historyBtn;

@end

@implementation LGServiceExpiresCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    //性别、年龄
    NSString *gender = LGNSString(dataDic[@"gender"]);
    NSString *age = LGNSString(dataDic[@"age"]);
    if(gender.length>0 && age.length >0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@  %@岁",gender,age];
    }else if (gender.length > 0 && age.length == 0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@",gender];
    }else if (gender.length == 0 && age.length>0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@岁",age];
    }else{
        self.ageLabel.text = @"";
    }
    self.timeLabel.text = LGNSString(dataDic[@"vip_date_end"]);;
    self.serviceLabel.text = LGNSString(dataDic[@"title"]);
}

-(void)patientBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(checkPatientDetail:)]){
        [self.delegate checkPatientDetail:self.dataDic];
    }
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.patientBtn];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.timeTitle];
    [self.baseView addSubview:self.timeLabel];
    [self.baseView addSubview:self.serviceTitle];
    [self.baseView addSubview:self.serviceLabel];
    [self.baseView addSubview:self.historyBtn];

    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.baseView).offset(viewPix(12));
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
    }];
    
    [self.patientBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.baseView);
        make.height.equalTo(@(viewPix(42)));
    }];
  
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(42));
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.height.equalTo(@(0.5));
    }];
    [self.timeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(viewPix(12));
        make.width.equalTo(@(viewPix(60)));
        make.left.equalTo(self.nameLabel);
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.serviceTitle.mas_right).offset(viewPix(12));
        make.centerY.equalTo(self.timeTitle);
    }];
    [self.serviceTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeTitle.mas_bottom).offset(viewPix(14));
        make.left.width.equalTo(self.timeTitle);
    }];
    [self.serviceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.serviceTitle.mas_right).offset(viewPix(12));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.top.equalTo(self.serviceTitle);
        make.bottom.equalTo(self.baseView).offset(-viewPix(12));
    }];
    [self.historyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.timeTitle);
        make.width.equalTo(@(viewPix(70)));
        make.height.equalTo(@(viewPix(20)));
    }];
}


-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}



-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}

-(UILabel *)timeTitle{
    if(!_timeTitle){
        _timeTitle = [UILabel lableWithText:@"到期时间" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeTitle;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UILabel *)serviceTitle{
    if(!_serviceTitle){
        _serviceTitle = [UILabel lableWithText:@"服务包" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _serviceTitle;
}

-(UILabel *)serviceLabel{
    if(!_serviceLabel){
        _serviceLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _serviceLabel;
}

-(UIButton *)patientBtn{
    if(!_patientBtn){
        _patientBtn = [UIButton buttonWithImage:@"grayTip16" frame:CGRectMake(0, 0, Screen_W-viewPix(32), viewPix(42))];
        _patientBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _patientBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, viewPix(12));
        [_patientBtn addTarget:self action:@selector(patientBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _patientBtn;
}

-(UIButton *)historyBtn{
    if(!_historyBtn){
        _historyBtn = [UIButton buttonWithTitle:@"签约历史" titleFont:LGFont(14) textColor:@"#4C87FD" imageName:@"blueTip12"];
        _historyBtn.bounds = CGRectMake(0, 0, viewPix(70), viewPix(20));
        _historyBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_historyBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
        _historyBtn.userInteractionEnabled = NO;
    }
    return _historyBtn;
}


@end
